package com.jjiang.bbmall.member.web;

import com.jjiang.bbmall.member.feign.OrderFeignService;
import com.jjiang.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.Map;

@Controller
public class MemberWebController {

    @Autowired
    OrderFeignService orderFeignService;

    @GetMapping("/list.html")
    public String list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, Model model) {
        // 查询出当前登录的用户的所有订单列表数据
        Map<String, Object> pageParam = new HashMap<>();
        pageParam.put("page", pageNum.toString());
        // 需要带上cookie，以便与登录的访问order接口
        R r = orderFeignService.listWithItem(pageParam);
        if (r.getCode() == 0) {
            model.addAttribute("orders", r);
        }
        return "list";
    }
}
